package com.bosssoft.trainee.nontax.controller;

import com.bosssoft.trainee.nontax.common.Result;
import com.bosssoft.trainee.nontax.entity.po.Permission;
import com.bosssoft.trainee.nontax.service.IPermissionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/permission")
public class PermissionController extends BaseController {

    @Resource
    private IPermissionService permissionService;

    @PostMapping
    public Result<?> save(@RequestBody Permission permission) {
        permissionService.save(permission);
        return Result.success();
    }

    @PutMapping
    public Result<?> update(@RequestBody Permission permission) {
        permissionService.updateById(permission);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result<?> update(@PathVariable Long id) {
        permissionService.removeById(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result<?> getById(@PathVariable Long id) {
        return Result.success(permissionService.getById(id));
    }

    @GetMapping("/all")
    public Result<?> all() {
        return Result.success(permissionService.list());
    }

    @GetMapping
    public Result<?> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "10") Integer pageSize,
                              @RequestParam(defaultValue = "") String search) {
        return permissionService.findPage(pageNum, pageSize, search);
    }
}
